<template>
  <div class="dashboard-container">
    <div class="header">
      <h1>论坛主界面</h1>
      <div class="user-info">
        <span>{{ user.username }}</span>
        <button @click="logout">退出登录</button>
      </div>
    </div>
    
    <div class="content">
      <h2>欢迎回来，{{ user.username }}</h2>
      <p>请选择您要访问的功能</p>
      
      <div class="function-cards">
        <div class="card" @click="goToPostOverview">
          <i class="fa fa-th-list"></i>
          <h3>帖子总览</h3>
          <p>浏览和搜索所有帖子</p>
        </div>
        
        <div class="card" @click="goToUserPosts">
          <i class="fa fa-file-text-o"></i>
          <h3>我的帖子</h3>
          <p>管理您发布的帖子</p>
        </div>
        
        <div class="card" @click="goToUserProfile">
          <i class="fa fa-user"></i>
          <h3>个人资料</h3>
          <p>查看和编辑个人信息</p>
        </div>
        
        <div class="card" @click="goToCreatePost" v-if="user.userType !== 'admin'">
          <i class="fa fa-pencil"></i>
          <h3>发布帖子</h3>
          <p>创建新的帖子内容</p>
        </div>
        
        <div class="card" @click="goToAdminDashboard" v-if="user.userType === 'admin'">
          <i class="fa fa-cog"></i>
          <h3>管理后台</h3>
          <p>管理用户和帖子</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'

const router = useRouter()
const userStore = useUserStore()

const user = computed(() => userStore.user)

const logout = () => {
  userStore.logout()
  router.push('/login')
}

const goToPostOverview = () => {
  router.push({ name: 'PostOverview' })
}

const goToUserPosts = () => {
  router.push({ name: 'UserPosts' })
}

const goToUserProfile = () => {
  router.push({ name: 'UserProfile' })
}

const goToCreatePost = () => {
  router.push({ name: 'CreatePost' })
}

const goToAdminDashboard = () => {
  router.push({ name: 'AdminDashboard' })
}
</script>


<style scoped>
.dashboard-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background-color: #2c3e50;
  color: white;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 20px;
}

.user-info button {
  background-color: #e74c3c;
  color: white;
  border: none;
  padding: 8px 15px;
  border-radius: 4px;
  cursor: pointer;
}

.content {
  flex: 1;
  padding: 40px;
  text-align: center;
}

.function-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-top: 40px;
}

.card {
  background-color: white;
  border-radius: 8px;
  padding: 30px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: transform 0.3s;
}

.card:hover {
  transform: translateY(-5px);
}

.card i {
  font-size: 48px;
  color: #2196F3;
  margin-bottom: 20px;
}

.card h3 {
  margin-bottom: 10px;
}

.card p {
  color: #666;
}
</style>    